package network;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestInet {

    public static void main(String[] args) {
        try {
            InetAddress name1 = InetAddress.getByName("127.0.0.1");
            System.out.println(name1);
            InetAddress name2 = InetAddress.getByName("localhost");
            System.out.println(name1);
            InetAddress name3 = InetAddress.getLocalHost();
            System.out.println(name1);

            //查询网站IP-百度
            InetAddress nameBaidu = InetAddress.getByName("www.baidu.com");
            System.out.println(nameBaidu);
            //System.out.println(nameBaidu.getAddress());
            System.out.println(nameBaidu.getCanonicalHostName());//规范域名
            System.out.println(nameBaidu.getHostAddress());//域名地址
            System.out.println(nameBaidu.getHostName());//域名
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
